﻿using System.Collections.Generic;
using System.Linq;
using System.Models;
using System.Models.Models;

namespace System.DataInitialization.ModelsData
{
    public class JurisdictionData
    {
        private MyDbContext db;
        private Jurisdiction list;
        private List<Jurisdiction> lists;
        public JurisdictionData()
        {
            db = new MyDbContext();
            lists = new List<Jurisdiction>();
        }

        public void AddData()
        {
            var MenusLists = db.Menuss.ToList();
            //Console.WriteLine(MenusLists.Count()); //测试条数
            for(int i = 2; i <= MenusLists.Count(); i++)
            {
                list = new Jurisdiction()
                {
                    PowerName = "超级管理员权限",
                    MenusId = i,
                    DepartmentRoleId = 1,
                };

                Console.WriteLine($"PowerName是{list.PowerName},MenusId是{list.MenusId},DepartmentRoleId是{list.DepartmentRoleId}"); //测试数据MenusId的变动
                lists.Add(list);
            }

            Console.WriteLine("----------------------------------------------------------------");

            foreach(var li in lists)
            {
                //Console.WriteLine($"PowerName是{li.PowerName},MenusId是{li.MenusId},DepartmentRoleId是{li.DepartmentRoleId}"); //测试数据MenusId的变动
                db.Jurisdictions.Add(li);
            }

            db.SaveChanges();
            Console.WriteLine("权限表数据初始化成功");
        }

    }
}
